package sg.nus.iss.vmcs.guilisteners;

import java.awt.TextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import sg.nus.iss.vmcs.controllers.MaintenanceController;
import sg.nus.iss.vmcs.gui.MessageDialog;

/**
 * Action Listener for the Price Display in the Drinks Display Panel at the Maintenance Panel <br><br>
 * Modifications:
 * <li>Philip - 28/12/2010 - Removed temporary variables in actionPerformed</li>
 * <br><br>
 * @author Pang Pingli
 * @author Philip Chew
 */
public class PriceDisplayListener implements ActionListener {
	
	/** Maintenance Controller */
	private MaintenanceController  mctrl;

	/**
	 * Creates an instance of the Price Display Listener
	 * @param mc Reference to Maintenance Controller
	 */
	public PriceDisplayListener(MaintenanceController  mc) {
		mctrl = mc;
  	}
  
	/**
	 * Implementation of Action Performed
	 */
	public void actionPerformed(ActionEvent e) {
		try {
			int price = Integer.parseInt(((TextField)e.getSource()).getText());
			mctrl.setPrice(price);
		}
		catch(NumberFormatException ee) {
		    new MessageDialog(mctrl.getMaintenancePanel(), MessageDialog.NUMBER_FORMAT_ERROR);
		    return;
		}
	}
}